package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.GoodsTypeDao;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.entity.vo.GoodsTypeVo;
import com.atguigu.jxc.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author Mr.zhao
 */
@Service
public class GoodsTypeServiceImpl implements GoodsTypeService {

    @Autowired
    private GoodsTypeDao goodsTypeDao;

    @Override
    public List<GoodsTypeVo> getGoodsTypes() {

        List<GoodsTypeVo> goodsTypes = goodsTypeDao.getGoodsTypes();
        for (GoodsTypeVo goodsType : goodsTypes) {
            Integer pid = goodsTypeDao.getGoodsTypesPid(goodsType.getId());

            if (pid == 1 || pid == -1){
                goodsType.getAttributes().put("state","1");
            }else {
                goodsType.getAttributes().put("state","0");
            }

        }


        return goodsTypes;

    }

    @Override
    public void save(String goodsTypeName, Integer pId) {
        goodsTypeDao.save(goodsTypeName,pId);
    }

    @Override
    public void delete(Integer goodsTypeId) {
        goodsTypeDao.delete(goodsTypeId);
    }
}
